package khiem.java.sample.genericgrapth;

import java.util.ArrayList;
import java.util.List;

public class GraphNode implements Comparable<GraphNode> {
  private String name;
  private String version;
  private List<Dependency> dependencies = new ArrayList<Dependency>();  
  
  public GraphNode(String name, String version) {
    this.name = name;
    this.version = version;
  }
  
  public String getName() {
    return name;
  }

  public void setName(String name) {
    this.name = name;
  }
  
  public String getVersion() {
    return version;
  }

  public void setVersion(String version) {
    this.version = version;
  }

  public List<Dependency> getDependencies() {
    return dependencies;
  }

  public void setDependencies(List<Dependency> dependencies) {
    this.dependencies = dependencies;
  }

  public void addDependency(String targetNode, String operator, String targetVersion) {
    this.dependencies.add(new Dependency(targetNode, operator, targetVersion));
  }
  
  public void addDependency(String targetNode, String operator, String targetVersion, String operator2, String targetVersion2) {
    this.dependencies.add(new Dependency(targetNode, operator, targetVersion, operator2, targetVersion2));
  }
  
  @Override
  public boolean equals(Object o) {
    GraphNode target = (GraphNode) o;
    return (this.name.equalsIgnoreCase(target.getName()) && this.version.equalsIgnoreCase(target.getVersion()));
  }
  
  @Override
  public String toString() {
    return "(" + this.name + ", " + this.version + ")";
  }
  
  @Override
  public int compareTo(GraphNode o) {
    if (!name.equals(o.getName())) return 0;
    else return version.compareTo(o.getVersion());
  }
}
